package com.qingke.stockdata.mappers;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.qingke.stockdata.exception.NoResultException;
import com.qingke.stockdata.model.Stock;
import com.qingke.stockdata.model.StockData;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:springConfig.xml"})
public class StockDaoTest {
	
	@Autowired
	private StockDao stockDao;

	@Test
	public void testSelectStockByCode() {
		String code = "sh601006";
		Stock stock;
		try {
			stock = stockDao.selectStockByCode(code);
			System.out.println(stock);
		} catch (NoResultException e) {
			e.printStackTrace();
		}
	}

	@Test
	public void testSelectStockByUser() {
		int userId = 1;
		List<Stock> stocks;
		try {
			stocks = stockDao.selectStockByUser(userId);
			for (Stock stock : stocks) {
				System.out.println(stock);
			}
		} catch (NoResultException e) {
			e.printStackTrace();
		}
	}

	@Test
	public void testAddStock() {
		Stock stock = new Stock();
		stock.setCode("sh0124545");
		stock.setName("鹏睿");
		stock.setHisotryLow(8.99);
		stock.setHistoryHigh(9.99);
		stockDao.addStock(stock);
	}

	@Test
	public void testSelectAllStockDetail() {
		String code = "sh601006";
		List<StockData> stockDatas;
		try {
			stockDatas = stockDao.selectAllStockDetail(code, 2, 0);
			for (StockData stockData : stockDatas) {
				System.out.println(stockData);
			}
		} catch (NoResultException e) {
			e.printStackTrace();
		}
	}

	@Test
	public void testAddStockDetail() {
		
		List<StockData> list = new ArrayList<StockData>();
		StockData stockData = new StockData();
		stockData.setCode("sh1597534682");
		stockData.setDate(new Date());
		stockData.setOpen(10.99);
		stockData.setLow(26.2);
		stockData.setHigh(27.55);
		stockData.setClose(10.99);
		stockData.setVolumn(10899);
		stockData.setAdjclose(10.99);
		list.add(stockData);
		int count = stockDao.addStockDetail(list);
		System.out.println(count);
	}

}
